<template>
  <div class="admin-demo" data-v-admindemo>
    <div class="top-box">
      <div class="header">
        <h2>Nobo</h2>
        <el-dropdown trigger="click">
          <span
            class="el-dropdown-link"
            style="font-size: 20px; cursor: pointer"
          >
            {{ username }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-switch-button"
              ><span @click="logout">退出</span></el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div class="body-box">
      <div class="aside">
        <el-menu
          :default-active="this.$route.path"
          class="el-menu-vertical-demo"
          :router="true"
        >
          <el-menu-item index="/admin/demo/home">
            <i class="el-icon-setting"></i>
            <span slot="title">发送通知</span>
          </el-menu-item>
          <el-menu-item index="/admin/demo/video">
            <i class="el-icon-setting"></i>
            <span slot="title">视频审核</span>
          </el-menu-item>
          <el-menu-item index="/admin/demo/complaint">
            <i class="el-icon-setting"></i>
            <span slot="title">投诉审核</span>
          </el-menu-item>
        </el-menu>
      </div>
      <div class="main">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import jwt_decode from "jwt-decode";

export default {
  name: "AdminDemo",
  data: function () {
    return {
      username: "",
    };
  },

  created() {
    this.getToken();
    this.$socket.open(); // 开始连接socket
  },

  methods: {
    getToken() {
      let token = localStorage.getItem("token");
      let decoded = jwt_decode(token);
      this.username = decoded.username;
    },

    logout() {
      localStorage.removeItem("token");
      this.$router.push("/admin/login");
    },
  },
};
</script>

<style lang="scss" scoped>
.admin-demo[data-v-admindemo] {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;

  .top-box {
    width: 100%;
    height: 80px;
    background-color: #409eff;

    .header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 100%;
      padding: 0 20px;

      h2 {
        font-size: 24px;
        font-weight: 500;
        color: #fff;
      }

      span {
        font-size: 18px;
        color: #fff;
      }
    }
  }

  .body-box {
    display: flex;
    width: 100%;
    flex: 1;

    .aside {
      width: 300px;
      height: 100%;

      .el-menu-vertical-demo {
        height: 100%;
      }
    }

    .main {
      height: 100%;
      flex: 1;
      background-color: #fff;
    }
  }
}
</style>